﻿@page "/system_manager/systimer"
@inherits ListOperateTableBase<SysTimerDto, int, SysTimerEdit, SysTimerLocalResource>

<div>
    <Table @ref="_table"
           TItem="SysTimerDto"
           DataSource="@_datas"
           Total="_total"
           OnChange="@OnChange"
           @bind-PageIndex="_pageIndex"
           @bind-PageSize="_pageSize"
           @bind-SelectedRows="_selectedRows"
           Loading="@_tableLoading.Value"
           Context="model">
        <TitleTemplate>
            <ResourceAuthorize ResourceKey="system_manager_timer_refresh">
                <TableSearch TDto="SysTimerDto" OnSearch="OnTableSearch" @ref="this._tableSearch" Settings="_tableSearchSettings" CustomLocalizer="Localizer"></TableSearch>
            </ResourceAuthorize>
            <Row>
                <AntDesign.Col Span="8">
                    <ResourceAuthorize ResourceKey="system_manager_timer_delete_selected">
                        <Button Type="@ButtonType.Primary" Icon="delete" Danger OnClick="OnClickDeletes" Loading="_deletesBtnLoading">
                            @Localizer[SharedLocalResource.DeleteSelected]
                        </Button>
                    </ResourceAuthorize>
                </AntDesign.Col>
                <AntDesign.Col Span="16" Style="text-align:right">
                    <Space>
                        <ResourceAuthorize ResourceKey="system_manager_timer_add">
                            <SpaceItem>
                                <Button Type="@ButtonType.Primary" Icon="plus" OnClick="OnClickAdd">
                                    @Localizer[SharedLocalResource.Add]
                                </Button>
                            </SpaceItem>
                        </ResourceAuthorize>
                        <ResourceAuthorize ResourceKey="system_manager_timer_refresh">
                            <SpaceItem>
                                <Button Type="@ButtonType.Primary" Icon="reload" OnClick="ReLoadTable">
                                    @Localizer[SharedLocalResource.Refresh]
                                </Button>
                            </SpaceItem>
                        </ResourceAuthorize>
                        <ResourceAuthorize ResourceKey="system_manager_timer_export">
                            <SpaceItem>
                                <Button Type="@ButtonType.Primary" Icon="export" OnClick="OnClickExport" Loading="_exportDataLoading">
                                    @Localizer[SharedLocalResource.Export]
                                </Button>
                            </SpaceItem>
                        </ResourceAuthorize>
                    </Space>
                </AntDesign.Col>
            </Row>
        </TitleTemplate>
        <ColumnDefinitions>
            <ResourceAuthorize ResourceKey="system_manager_timer_delete_selected">
                <Selection Key="@(model.Id.ToString())" />
            </ResourceAuthorize>
             <Column @bind-Field="@model.JobName" Filterable Title="@Localizer[SysTimerLocalResource.JobName]" />
             <Column @bind-Field="@model.ExecuteType" Width="10%" Filters="FunctionExecuteTypeFilters()" Title="@Localizer[SysTimerLocalResource.ExecuteType]">
                 <TagPro Text="@model.ExecuteType">@Localizer[EnumHelper.GetEnumDescriptionOrName(model.ExecuteType)]</TagPro>
            </Column>
             <Column TData="string" Ellipsis Title="@Localizer[SysTimerLocalResource.ExecuteContent]">
                @if (ExecuteType.LOCAL_METHOD.Equals(model.ExecuteType))
                {
                    <Tooltip Title="@model.LocalMethod" Placement="Placement.Top">
                        <span>@model.LocalMethod</span>
                    </Tooltip>
                }
                else if (ExecuteType.HTTP.Equals(model.ExecuteType))
                {
                    <span>@EnumHelper.GetEnumDescription(model.HttpMethod)</span>
                    <br />
                    <span>@model.RequestUrl</span>
                    <br />
                    <span>@model.RequestParameters</span>
                    <br />
                    <span>@model.Headers</span>
                }
            </Column>
            <Column TData="string" Title="@Localizer[SysTimerLocalResource.Scheduling]">
                @if (model.TimerType.Equals(TimerTypes.Cron))
                {
                    <span>@model.Cron</span>
                }
                else if (model.TimerType.Equals(TimerTypes.Interval))
                {
                    <span>@model.Interval</span>

                    <span>秒</span>
                }
            </Column>
            <Column @bind-Field="@model.TimerStatus" Width="10%" Title="@Localizer[SysTimerLocalResource.TimerStatus]" Filters="FunctionTimerStatusFilters()">
                <TagPro Text="@model.TimerStatus">@Localizer[EnumHelper.GetEnumDescriptionOrName(model.TimerStatus)]</TagPro>
                <Tooltip Title="@($"{Localizer[SysTimerLocalResource.Executed]} {(model.RunNumber.HasValue ? model.RunNumber.Value : 0)} {Localizer[SysTimerLocalResource.Times]}")">
                    <Badge Count="(int)(model.RunNumber.HasValue ? model.RunNumber.Value : 0)"
                           Style="background-color: #52c41a; " />
                </Tooltip>
                <Tooltip Title="@($"{Localizer[SysTimerLocalResource.ExecutFailed]} {(model.RunErrorNumber.HasValue ? model.RunErrorNumber.Value : 0)} {Localizer[SysTimerLocalResource.Times]}")">
                    <Badge Count="(int)(model.RunErrorNumber.HasValue ? model.RunErrorNumber.Value : 0)"
                           Style="background-color: #52c41a; " />
                </Tooltip>
            </Column>
            <Column @bind-Field="@model.Remark" Ellipsis Filterable Title="@Localizer[SysTimerLocalResource.Remark]" />
            <Column @bind-Field="@model.CreatedTime" Format="@ClientConstant.DateTimeFormat" Sortable DefaultSortOrder="@SortDirection.Descending" Title="@Localizer[SharedLocalResource.CreatedTime]" />

            <ActionColumn>
                <Space>
                    <ResourceAuthorize ResourceKey="system_manager_timer_edit">
                        <SpaceItem>
                            <Tooltip Title="@(Localizer[SharedLocalResource.Edit])" ArrowPointAtCenter="true">
                                <Button Icon="edit" Type="@ButtonType.Primary" Size="@ClientConstant.OperationButtonSize" OnClick="()=>OnClickEdit(model.Id)"></Button>
                            </Tooltip>
                        </SpaceItem>
                    </ResourceAuthorize>
                    <ResourceAuthorize ResourceKey="system_manager_timer_detail">
                        <SpaceItem>
                            <Tooltip Title="@(Localizer[SharedLocalResource.Detail])" ArrowPointAtCenter="true">
                                <Button Icon="eye" Type="@ButtonType.Primary" Size="@ClientConstant.OperationButtonSize" OnClick="()=>OnClickDetail(model.Id)"></Button>
                            </Tooltip>
                        </SpaceItem>
                    </ResourceAuthorize>
                    <ResourceAuthorize ResourceKey="system_manager_timer_delete">
                        <SpaceItem>
                            <Tooltip Title="@(Localizer[SharedLocalResource.Delete])" ArrowPointAtCenter="true">
                                <Button Icon="delete" Type="@ButtonType.Primary" Danger OnClick="()=>OnClickDelete(model.Id)"></Button>
                            </Tooltip>
                        </SpaceItem>
                    </ResourceAuthorize>
                    <ResourceAuthorize ResourceKey="system_manager_timer_start">
                        @if (!TimerStatus.Running.Equals(model.TimerStatus))
                        {
                            <SpaceItem>
                                <Tooltip Title="@(Localizer[SharedLocalResource.Open])" ArrowPointAtCenter="true">
                                    <Button Icon="play-circle" Type="@ButtonType.Primary" Size="@ClientConstant.OperationButtonSize" OnClick="()=>OnStartExecute(model)"></Button>
                                </Tooltip>
                            </SpaceItem>
                        }
                    </ResourceAuthorize>
                    <ResourceAuthorize ResourceKey="system_manager_timer_stop">
                        @if (TimerStatus.Running.Equals(model.TimerStatus))
                        {
                            <SpaceItem>
                                <Tooltip Title="@(Localizer[SharedLocalResource.Close])" ArrowPointAtCenter="true">
                                    <Button Icon="pause-circle" Danger Type="@ButtonType.Primary" Size="@ClientConstant.OperationButtonSize" OnClick="()=>OnStartExecute(model)"></Button>
                                </Tooltip>
                            </SpaceItem>
                        }
                    </ResourceAuthorize>
                </Space>
            </ActionColumn>
        </ColumnDefinitions>
    </Table>
</div>
